package com.chinairi.mall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chinairi.mall.model.ServiceShelfGoodsType;
import com.chinairi.mall.dao.ServiceShelfGoodsTypeMapper;
import com.chinairi.mall.model.ServiceShelfPriceAdd;
import com.chinairi.mall.model.ServiceShelfPriceMulti;
import com.chinairi.mall.model.ServiceType;
import com.chinairi.mall.service.IServiceShelfGoodsTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务_商品分类表 服务实现类
 * </p>
 *
 * @author Webgasd
 * @since 2020-09-18
 */
@Service
public class ServiceShelfGoodsTypeServiceImpl extends ServiceImpl<ServiceShelfGoodsTypeMapper, ServiceShelfGoodsType> implements IServiceShelfGoodsTypeService {
    @Autowired
    private ServiceShelfGoodsTypeMapper serviceShelfGoodsTypeMapper;

    public List<ServiceShelfGoodsType> getTypeList(String dbId) {
        QueryWrapper<ServiceShelfGoodsType> wrapper = new QueryWrapper<>();
        wrapper
                .eq(StringUtils.isNotEmpty(dbId), "SGT_SER_CLASS_CODE", dbId);
        return serviceShelfGoodsTypeMapper.selectList(wrapper);
    }

    /**
     * 根据服务分类小类获取小类下的所有商品类别
     *
     * @param dbId
     * @return
     */
    @Override
    public List<ServiceShelfPriceAdd> getTypeAddList(String dbId) {
        List<ServiceShelfGoodsType> resultList = this.getTypeList(dbId);
        List<ServiceShelfPriceAdd> list = new ArrayList<>();

        for (ServiceShelfGoodsType serviceShelfGoodsType : resultList) {
            ServiceShelfPriceAdd serviceShelfPriceAdd = new ServiceShelfPriceAdd();
            serviceShelfPriceAdd.setSgtDbid(serviceShelfGoodsType.getSgtDbid());
            serviceShelfPriceAdd.setSgtName(serviceShelfGoodsType.getSgtGoodsSerClassName());
            serviceShelfPriceAdd.setSspDataBoundry(0);
            serviceShelfPriceAdd.setSspPriceUnit(serviceShelfGoodsType.getSgtGoodsSerClassUnit());
            serviceShelfPriceAdd.setSspMChargePre(BigDecimal.valueOf(0));
            serviceShelfPriceAdd.setSspSChargePre(BigDecimal.valueOf(0));
            serviceShelfPriceAdd.setSspSChargeLater(BigDecimal.valueOf(0));
            serviceShelfPriceAdd.setSspSChargeLater(BigDecimal.valueOf(0));
            list.add(serviceShelfPriceAdd);
        }
        return list;
    }

    /**
     * 根据服务分类小类获取小类下的所有商品类别
     *
     * @param dbId
     * @return
     */
    @Override
    public List<ServiceShelfPriceMulti> getTypeMultiList(String dbId) {
        List<ServiceShelfGoodsType> resultList = this.getTypeList(dbId);
        List<ServiceShelfPriceMulti> list = new ArrayList<>();

        for (ServiceShelfGoodsType serviceShelfGoodsType : resultList) {
            ServiceShelfPriceMulti serviceShelfPriceMulti = new ServiceShelfPriceMulti();
            serviceShelfPriceMulti.setSgtDbid(serviceShelfGoodsType.getSgtDbid());
            serviceShelfPriceMulti.setSgtName(serviceShelfGoodsType.getSgtGoodsSerClassName());
            serviceShelfPriceMulti.setSpPriceUnit(serviceShelfGoodsType.getSgtGoodsSerClassUnit());
            serviceShelfPriceMulti.setSpServiceCharge(BigDecimal.valueOf(0));
            serviceShelfPriceMulti.setSpMangerCharge(BigDecimal.valueOf(0));
            list.add(serviceShelfPriceMulti);
        }
        return list;
    }
}
